package com.frxuexi.park2212.visit

import androidx.lifecycle.MutableLiveData
import com.frxuexi.lib_base.base.BaseViewModel
import com.frxuexi.lib_base.entity.VisitBean
import com.frxuexi.lib_base.entity.VisitBeanItem
import com.frxuexi.lib_base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class VisitViewModel @Inject constructor(val apiService: ApiService):BaseViewModel() {

    var getVisits = MutableLiveData<VisitBean>()
    var getVisitById = MutableLiveData<VisitBeanItem>()

    var approveVisit = MutableLiveData<VisitBeanItem>()
    var rejectVisit = MutableLiveData<VisitBeanItem>()
    var deleteVisit = MutableLiveData<Boolean>()
    var addVisit = MutableLiveData<VisitBeanItem>()

    fun getVisits(){
        httpRequest({apiService.getVisits()},getVisits::postValue)
    }

    fun getVisitByStatus(status:String){
        httpRequest({apiService.getVisitByStatus(status)},getVisits::postValue)
    }

    fun getVisitById(id:Int){
        httpRequest({apiService.getVisitById(id)},getVisitById::postValue)
    }

    fun approveVisit(id:Int){
        httpRequest({apiService.approveVisit(id)},approveVisit::postValue)
    }

    fun rejectVisit(id:Int){
        httpRequest({apiService.rejectVisit(id)},rejectVisit::postValue)
    }

    fun deleteVisit(id:Int){
        httpRequest({apiService.deleteVisit(id)},deleteVisit::postValue)
    }

    fun  addVisit(beanItem: VisitBeanItem){
        httpRequest({apiService.addVisit(toBody(beanItem))},addVisit::postValue)
    }
}